package com.herysoft.scm.log;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;
import java.lang.reflect.Method;
public class LogIntercepter implements MethodInterceptor {

	public Object invoke(MethodInvocation method) throws Throwable {
		Logger log=Logger.getLogger(method.getThis().getClass());
		
		Method m = method.getMethod();
		Object[] params = method.getArguments();
		StringBuffer msg = new StringBuffer();
		msg.append(m.getName()+"||");
		for(Object param :params)
			msg.append(param+"||");
		Object result = null;
		try{
			result = method.proceed();
			msg.append(result+"||TRUE");
		}catch(Exception ex){
			msg.append("||ex:"+ex.getMessage()+"||FALSE");
		}
		log.info(msg);
		return result;
	}
}
